package main

import (
	"context"
	"log"
	"net/http"

	"github.com/cloudwego/hertz/pkg/app"
	"github.com/cloudwego/hertz/pkg/route"
	_ "github.com/go-sql-driver/mysql"
	"github.com/hertz-contrib/paseto"
	"hertz-nbdemo/biz/service/impl"
	casbinPkg "hertz-nbdemo/pkg/casbin"
	"hertz-nbdemo/util/common"
)

func registerV1(v1 *route.RouterGroup) {
	v1.GET("/ping", func(ctx context.Context, c *app.RequestContext) {
		c.JSON(http.StatusOK, common.SimpleSuccess())
	})
	auth, err := casbinPkg.NewCasbinAuthenticator()
	if err != nil {
		log.Fatal(err)
	}
	sseService := impl.NewSseService()
	pasetoService := impl.NewPasetoService()
	voloService := impl.NewVoloService()
	casbinService := impl.NewCasbinService()

	v1.POST("/login", pasetoService.Login)
	v1.POST("/register", pasetoService.Register)
	pasetoMw := paseto.New(paseto.WithTokenPrefix("Bearer "))
	v1.POST("/paseto", pasetoMw, pasetoService.TestToken)

	v1.GET("/sse", sseService.TestSse)

	v1.GET("/volo", voloService.Volo)

	v1.GET("/casbin/r",
		auth.RequiresPermissions("book:read"),
		casbinService.R)
	v1.GET("/casbin/u",
		auth.RequiresRoles("user"),
		casbinService.U)
}
